Nova shape

Imports

In [1]:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
import numpy as np
import matplotlib.cm as cm
import matplotlib.colors as cls
from pandas import Series, DataFrame
from mpl_toolkits.axes_grid1.inset_locator import inset_axes, zoomed_inset_axes, mark_inset
import matplotlib.ticker as ticker
from collections import defaultdict, namedtuple
from pandas import ExcelWriter
import xlsxwriter
import pandas as pd
import calendar
import pickle
import datetime
from scipy import stats
import itertools
import statistics
# set seaborn plot style
import seaborn as sns 
sns.set()
sns.set_context("paper")
sns.set_style("whitegrid")
# set default font 
plt.rcParams["font.family"] = "Times New Roman"
In [7]:
def get_ecos():
    m = Basemap(projection='cyl')
    shpf = m.readshapefile('C:/Users/alpha/Documents/MODIS/MCD64A1/newreprojected/newreprojected','ecos',linewidth=0.1)
    return m.ecos_info, m.ecos
In [6]:
m = Basemap(projection='cyl')
shpf = m.readshapefile('C:/Users/alpha/Documents/MODIS/MCD64A1/newreprojected/newreprojected','ecos',linewidth=0.1)
ecos_info, ecos = m.ecos_info, m.ecos
In [4]:
%qtconsole
In [10]:
ecos_info[0].keys()
Out[10]:
dict_keys(['OBJECTID', 'ECO_NAME', 'BIOME_NUM', 'BIOME_NAME', 'REALM', 'ECO_BIOME_', 'NNH', 'ECO_ID', 'ID', 'GRIDCODE', 'FIPS_CNTRY', 'CNTRY_NAME', 'CONTINENT', 'Clima_Name', 'Area_polig', 'RINGNUM', 'SHAPENUM'])
In [11]:
months = [calendar.month_name[i +1][:3] for i in range(12)]
In [12]:
years = [str(y) for y in range(2001,2018)]
In [42]:
ecoids =  [e['ECO_ID'] for e in ecos_info]
bionums =  [e['BIOME_NUM'] for e in ecos_info]
bionames = [e['BIOME_NAME'] for e in ecos_info]
ids = [e['ID'] for e in ecos_info]
climes = [e['GRIDCODE'] for e in ecos_info]
continents = [e['CONTINENT'] for e in ecos_info]
countries = [e['FIPS_CNTRY'] for e in ecos_info]
areas= [e['Area_polig'] for e in ecos_info]
In [59]:
for i ,id in enumerate(ecoids):
    if id == 0:
        bionums[i] = 0.0
        
In [20]:
result = {}
for i in range(1,18):
    suf = '20{0:02d}'.format(i)
    in_file= 'newresult' + suf
    result[suf] = DataFrame(np.load(in_file), columns =months)
In [60]:
for i in range(1,18):
    suf = '20{0:02d}'.format(i)
    result[suf] = result[suf].assign(eco_id=ecoids,biome_num =bionums,biome_name=bionames,idd=ids,clime=climes,continent=continents,country=countries, area = areas)
    
In [92]:
grouped = result['2001'][ ['eco_id','continent','clime','country','idd' ,'area'] ].groupby(['eco_id','continent','clime','country','idd' ,'area'])
areas_row = []
for a, _ in grouped:
    areas_row.append(a[-1])
len(areas_row)
In [105]:
attrs_table = {}
for yr, df in result.items():
    
    attrs_table[yr] =   df[ months + ['eco_id','continent','clime','country','idd','biome_num' ,'area']].groupby(['eco_id','continent','clime','country','idd','biome_num','area']).sum()
In [110]:
at_table = pd.concat(attrs_table)

Excel

In [111]:
writer = ExcelWriter('newshape.xlsx',engine='xlsxwriter')
In [112]:
at_table.to_excel(writer,sheet_name='Burned Pixels',engine='xlsxwriter')
In [113]:
writer.save()
In [206]:
plt.rcParams['mathtext.fontset'] = 'custom'

plt.rcParams['mathtext.rm'] = "Times New Roman"
plt.rcParams['mathtext.it'] = "Times New Roman"
plt.rcParams['mathtext.bf'] = "Times New Roman"
In [207]:
g = sns.regplot(np.arange(12),attrs_table['2002'].sum()/1e6, fit_reg= False)
ylabels = g.get_yticklabels()
g.set_xticklabels(months[::2], fontsize=15)
g.set_xticks(np.arange(0,12,2))
g.set_ylabel('Burned Pixels $(10^6)$', fontsize=15)
plt.setp(ylabels,fontsize=15)
#g.set(xticklabels=months[::2],xticks=np.arange(0,12,2), ylabel='Burned Pixels $(10^6)$', ylabelsize=15)
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1316: UserWarning: findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
In [210]:
plt.plot(np.arange(12),attrs_table['2002'].sum()/1e6)
g =plt.gca()
ylabels = g.get_yticklabels()
g.set_xticklabels(months[::2], fontsize=15)
g.set_xticks(np.arange(0,12,2))
g.set_ylabel('Burned Pixels $(10^6)$', fontsize=15)
plt.setp(ylabels,fontsize=15)
#g.set(xticklabels=months[::2],xticks=np.arange(0,12,2), ylabel='Burned Pixels $(10^6)$', ylabelsize=15)
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1316: UserWarning: findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
In [211]:
plt.scatter(np.arange(12),attrs_table['2002'].sum()/1e6)
g =plt.gca()
ylabels = g.get_yticklabels()
g.set_xticklabels(months[::2], fontsize=15)
g.set_xticks(np.arange(0,12,2))
g.set_ylabel('Burned Pixels $(10^6)$', fontsize=15)
plt.setp(ylabels,fontsize=15)
#g.set(xticklabels=months[::2],xticks=np.arange(0,12,2), ylabel='Burned Pixels $(10^6)$', ylabelsize=15)
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1316: UserWarning: findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
In [215]:
at_table.shape
Out[215]:
(141338, 12)
In [221]:
at_table.loc['2001',0,'Antarctica']
Out[221]:
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
clime country idd biome_num area
61 AY 2250 0.0 4.032087e+02 0 0 0 0 0 0 0 0 0 0 0 0
2251 0.0 3.897763e+02 0 0 0 0 0 0 0 0 0 0 0 0
2252 0.0 2.005869e+02 0 0 0 0 0 0 0 0 0 0 0 0
2256 0.0 4.046723e+01 0 0 0 0 0 0 0 0 0 0 0 0
2258 0.0 2.179660e+04 0 0 0 0 0 0 0 0 0 0 0 0
2259 0.0 3.684520e+07 0 0 0 0 0 0 0 0 0 0 0 0
In [222]:
at_table.sum()
Out[222]:
Jan    30800908
Feb    16221338
Mar    12309268
Apr    11253644
May    15388936
Jun    24553911
Jul    33778473
Aug    44192052
Sep    43896037
Oct    31921939
Nov    30386984
Dec    38894776
dtype: int64

Variação intra-anual. Totais

In [246]:
fig, ax = plt.subplots()


ax.plot( np.arange(12),at_table.sum()/1e6)
ax.set_xticks(np.arange(12))
ax.set_xticklabels(months, fontsize=15)


ax.set_title('Intra-annual Variability',fontsize=15)
labels_x = ax.get_xticklabels()
labels_y = ax.get_yticklabels()
off =ax.get_yaxis().get_offset_text()
off.set_x(-.07)
off.set_fontsize(12)

plt.setp(labels_y,fontsize=15)

plt.ylabel(r"Burned Pixels $(10^6)$", fontsize = 15)
plt.tight_layout()
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1316: UserWarning: findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

Variação inter-anual. Totais

In [239]:
at_table.index.names = ['year', 'eco_id', 'continent', 'clime', 'country', 'idd', 'biome_num', 'area']
In [244]:
at_table.groupby('year').sum().sum(axis=1)
Out[244]:
year
2001    20017001
2002    21601531
2003    20402068
2004    21480644
2005    21312486
2006    20098073
2007    21642001
2008    19744974
2009    17803506
2010    19425530
2011    21410147
2012    21195778
2013    16571517
2014    17702862
2015    18023638
2016    17058786
2017    18107724
dtype: int64
In [245]:
fig, ax = plt.subplots()
labels = years[::2]
ax.plot(years, at_table.groupby('year').sum().sum(axis=1)/1e6)
ax.set_xticks(labels)
ax.set_xticklabels(labels, fontsize=15)
ax.set_title('Interannual Variability',fontsize=15)
labels_x = ax.get_xticklabels()
labels_y = ax.get_yticklabels()
off =ax.get_yaxis().get_offset_text()
off.set_x(-.07)
off.set_fontsize(12)
plt.setp(labels_y,fontsize=15)
plt.ylabel(r"Burned Pixels ($10^6$)", fontsize = 15)
plt.tight_layout()
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1316: UserWarning: findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

Variação intermensal. Totais

In [249]:
at_table.groupby('year').sum().values.flatten()
Out[249]:
array([2319011,  815133,  445990,  538747,  835497, 1631801, 1531829,
       3210855, 2585382, 1870352, 1784319, 2448085, 1958829,  972121,
        557961,  566423, 1064981, 1139497, 2194027, 3173290, 2697351,
       2325896, 2048271, 2902884, 2229620,  952302,  894140,  631331,
       1516807, 1257076, 1936903, 2618875, 2022925, 1957578, 1598245,
       2786266, 1566919, 1216009,  920816,  519218, 1105061, 1850407,
       1911330, 2438905, 2822091, 2612609, 2179764, 2337515, 2298968,
       1005001,  737459,  706158, 1035226, 1605018, 2469111, 2634162,
       2323310, 1778532, 2276045, 2443496, 1574294,  753697,  675181,
        568348,  844001, 1582890, 1927650, 2745483, 2659274, 1647649,
       2459642, 2659964, 1983250, 1261271,  975107,  508485,  955804,
       1411059, 2262189, 2846250, 3344323, 1947545, 1725265, 2421453,
       1892059, 1026041,  820055,  916643,  912921, 1328941, 1919663,
       2449628, 2793059, 1735587, 1834978, 2115399, 1395238,  891557,
        681944,  939043,  701325, 1278340, 1874278, 2217078, 2203874,
       1472587, 1890031, 2258211, 1674233,  832282,  824513,  535403,
        627466, 1543261, 2024110, 3185132, 2999880, 1720646, 1346617,
       2111987, 1634505, 1017223,  711257,  687217,  863449, 1455266,
       2107586, 2644712, 3803863, 2515018, 1563474, 2406577, 1886932,
       1134560,  768363,  789784, 1043139, 1854940, 2105791, 2595005,
       2818544, 2265791, 1823080, 2109849, 1911366,  889602,  537693,
        651184,  895389, 1444689, 1749732, 2252574, 1895317, 1220649,
       1310470, 1812852, 1579422,  950661,  853812,  685430,  674997,
       1305560, 1935492, 2310381, 2127946, 1953941, 1457520, 1867700,
       1567563,  868438,  784867,  771815,  736750, 1275005, 2063671,
       2429591, 2205965, 1622309, 1836105, 1861559, 2146718,  803180,
        466560,  626040,  784754, 1272006, 1802214, 2144001, 1795380,
       1453906, 1639672, 2124355, 1181981,  832260,  653550,  612375,
        791369, 1318155, 1962897, 2296130, 2797553, 1821344, 1613486,
       2226624])
In [251]:
ym = itertools.product(years,months)
In [262]:
ymlabels = [ m + ' ' + y[-2:] for y, m in ym]


fig, ax = plt.subplots(figsize=(16,12))
labels = ymlabels[::6]
ax.plot( np.arange(12*17),at_table.groupby('year').sum().values.flatten()/1e6)
ax.axhline(y=statistics.mean(at_table.groupby('year').sum().values.flatten()/1e6), color='r', linestyle='--', label='mean')
ax.set_xticks(np.arange(0,12*17,6))
ax.set_xticklabels(labels,fontsize=12, rotation=30)
labels_y = ax.get_yticklabels()
plt.setp(labels_y,fontsize=15)
plt.ylabel(r"Burned Pixels ($10^6$)", fontsize = 15)
ax.set_title('Intra-monthly Variability',fontsize=15)
plt.legend(fontsize=15)
#prop={'size': 6}
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1316: UserWarning: findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

Variação intra_anual em cada bioma

In [264]:
at_table.groupby('biome_num').sum()
Out[264]:
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
biome_num
0.0 99 0 5 0 1 8 4 2 3 0 6 32
1.0 1464592 2297884 3533148 1604892 689709 715707 1299233 2589968 3378718 2083583 1252563 1364433
2.0 1459997 1000962 646158 481591 348825 173495 221944 548562 785526 497557 306219 307187
3.0 5863 14405 73798 185540 262658 83443 3060 960 346 234 880 1524
4.0 142124 162789 669431 1189271 673115 852870 332380 718994 746548 606887 234634 109552
5.0 6187 14727 105861 141350 132423 99776 143368 251853 122667 32351 12764 5302
6.0 395 692 355001 425742 477132 800395 1729174 878311 235836 38696 1874 180
7.0 23884373 10566922 4775773 4022473 10409916 18011863 24564287 32029713 31576970 21564029 23620993 33384847
8.0 405037 205965 645690 1500124 843048 993656 1705000 2241659 1753918 1016078 161022 170776
9.0 2125087 1304037 869727 723034 437639 1168314 1560576 1571355 1068563 807803 951347 2090885
10.0 94639 57855 31735 19752 127678 227642 270937 400024 320555 175167 52283 42790
11.0 0 0 881 834 8476 86097 178843 168898 20360 723 0 0
12.0 146858 114456 114346 155730 73307 119400 156584 209361 149163 144474 121265 127577
13.0 1049376 434379 419621 750842 869362 1210156 1604015 2570168 3722914 4940736 3666287 1281322
14.0 16281 46265 68093 52469 35647 11089 9068 12224 13950 13621 4847 8369
In [283]:
at_table.loc['2001',0, 'Antarctica',61,'AY',2250 ]
Out[283]:
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
biome_num area
0.0 403.20874 0 0 0 0 0 0 0 0 0 0 0 0
In [291]:
areas = at_table.loc['2001'].index.get_level_values(6)
In [296]:
at_table.index.get_level_values(7)
Out[296]:
Float64Index([    403.20874,     389.77632,     200.58694,      40.46723,
                21796.59728, 36845200.7967,     639.71949,    1601.71011,
                  100.37356,     326.58566,
              ...
                  281.73181,  406154.62427,    9402.35303,    9011.43427,
                    6.92947,  107477.59522,    1410.74331,    9493.74925,
                 8280.51621,   14269.01684],
             dtype='float64', name='area', length=141338)
In [297]:
141338/17
Out[297]:
8314.0
In [303]:
all_areas =at_table.index.get_level_values(7)
In [312]:
at_table_cp = at_table.copy()
In [304]:
#at_table_cp.areas = all_areas
In [313]:
at_table_cp.reset_index(inplace=True)
In [325]:
agg_dict = {month : 'sum' for month in months}
In [326]:
div_17 = lambda  x: sum(x)/17
In [330]:
agg_dict['area'] = div_17
In [333]:
biomes_table = at_table_cp.groupby('biome_num').agg(agg_dict)
In [341]:
biomes_table[months].div(biomes_table['area'], axis =0)
Out[341]:
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
biome_num
0.0 0.000002 0.000000 1.246608e-07 0.000000 2.493215e-08 1.994572e-07 9.972861e-08 4.986431e-08 7.479646e-08 0.000000 1.495929e-07 7.978289e-07
1.0 0.146003 0.229072 3.522136e-01 0.159989 6.875593e-02 7.134762e-02 1.295183e-01 2.581895e-01 3.368187e-01 0.207709 1.248659e-01 1.360180e-01
2.0 0.725622 0.497480 3.211420e-01 0.239352 1.733668e-01 8.622741e-02 1.103067e-01 2.726366e-01 3.904082e-01 0.247287 1.521915e-01 1.526726e-01
3.0 0.015793 0.038803 1.987891e-01 0.499788 7.075200e-01 2.247698e-01 8.242700e-03 2.585945e-03 9.320177e-04 0.000630 2.370450e-03 4.105188e-03
4.0 0.016009 0.018337 7.540475e-02 0.133960 7.581971e-02 9.606733e-02 3.743930e-02 8.098753e-02 8.409121e-02 0.068360 2.642919e-02 1.233994e-02
5.0 0.002263 0.005386 3.871618e-02 0.051695 4.843060e-02 3.649073e-02 5.243348e-02 9.210932e-02 4.486258e-02 0.011832 4.668133e-03 1.939082e-03
6.0 0.000025 0.000044 2.278138e-02 0.027321 3.061886e-02 5.136353e-02 1.109658e-01 5.636362e-02 1.513424e-02 0.002483 1.202597e-04 1.155109e-05
7.0 2.148099 0.950362 4.295206e-01 0.361771 9.362409e-01 1.619940e+00 2.209248e+00 2.880669e+00 2.839951e+00 1.939413 2.124411e+00 3.002547e+00
8.0 0.054642 0.027786 8.710704e-02 0.202375 1.137317e-01 1.340495e-01 2.300136e-01 3.024118e-01 2.366129e-01 0.137074 2.172273e-02 2.303860e-02
9.0 3.252554 1.995895 1.331161e+00 1.106640 6.698287e-01 1.788164e+00 2.388541e+00 2.405039e+00 1.635490e+00 1.236384 1.456085e+00 3.200206e+00
10.0 0.032427 0.019824 1.087377e-02 0.006768 4.374794e-02 7.799987e-02 9.283459e-02 1.370653e-01 1.098358e-01 0.060020 1.791439e-02 1.466168e-02
11.0 0.000000 0.000000 7.296000e-05 0.000069 7.019398e-04 7.130121e-03 1.481088e-02 1.398728e-02 1.686113e-03 0.000060 0.000000e+00 0.000000e+00
12.0 0.072808 0.056744 5.668966e-02 0.077207 3.634363e-02 5.919529e-02 7.763011e-02 1.037955e-01 7.395098e-02 0.071626 6.011991e-02 6.324923e-02
13.0 0.068171 0.028219 2.725988e-02 0.048777 5.647644e-02 7.861548e-02 1.042018e-01 1.669661e-01 2.418520e-01 0.320965 2.381733e-01 8.323864e-02
14.0 0.112692 0.320231 4.713176e-01 0.363173 2.467370e-01 7.675446e-02 6.276575e-02 8.461056e-02 9.655737e-02 0.094280 3.354936e-02 5.792750e-02
In [338]:
biomes_table['area']
Out[338]:
biome_num
0.0     4.010885e+07
1.0     1.003127e+07
2.0     2.012063e+06
3.0     3.712376e+05
4.0     8.877836e+06
5.0     2.734284e+06
6.0     1.558294e+07
7.0     1.111884e+07
8.0     7.412604e+06
9.0     6.533595e+05
10.0    2.918492e+06
11.0    1.207511e+07
12.0    2.017052e+06
13.0    1.539336e+07
14.0    1.444737e+05
Name: area, dtype: float64
In [345]:
# for serialization:
tabelas = {'multindex': at_table, 'simpleindex':at_table_cp}
In [346]:
with open('tabelas','wb') as f:
    f.write(pickle.dumps(tabelas))
In [369]:
biomes_intra = biomes_table[months].div(biomes_table['area'], axis =0)
In [356]:
biome_names_dict = dict( (num, name) for num, name in zip(bionums, bionames))

Mesma escala

In [372]:
fig, ax = plt.subplots(5,3, figsize =(18,12) , sharey=True)
labels = months
ax = ax.ravel()
for i in range(15):
        #slope, intercept, r_value, p_value, std_err = stats.linregress(np.arange(12), monbio[i*3 + j])
        #ax[i][j].plot(months, intercept + slope*years_float, 'r', label=r"$R^2$: {:5.3f} ".format(r_value**2))
        ax[i].plot(months, biomes_intra.iloc[i], 'o')
        ax[i].set_xticks(np.arange(12)) 
        ax[i].set_xticklabels(labels,fontsize=15)
        labels_y = ax[i].get_yticklabels()
        plt.setp(labels_y,fontsize=15)
        ax[i].set_title(biome_names_dict[i],fontsize=15)
        #ax[i].legend(fontsize=15)         
fig.tight_layout()
plt.show()

Sem escala comum

In [373]:
fig, ax = plt.subplots(5,3, figsize =(18,12))
labels = months
ax = ax.ravel()
for i in range(15):
        #slope, intercept, r_value, p_value, std_err = stats.linregress(np.arange(12), monbio[i*3 + j])
        #ax[i][j].plot(months, intercept + slope*years_float, 'r', label=r"$R^2$: {:5.3f} ".format(r_value**2))
        ax[i].plot(months, biomes_intra.iloc[i], 'o')
        ax[i].set_xticks(np.arange(12)) 
        ax[i].set_xticklabels(labels,fontsize=15)
        labels_y = ax[i].get_yticklabels()
        plt.setp(labels_y,fontsize=15)
        ax[i].set_title(biome_names_dict[i],fontsize=15)
        #ax[i].legend(fontsize=15)         
fig.tight_layout()
plt.show()

Variação interanual em cada bioma

In [393]:
at_table_cp[at_table_cp.year == '2001'].groupby('biome_num').sum().div(biomes_table['area'], axis=0)[months]
Out[393]:
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
biome_num
0.0 0.000000 0.000000 0.000000e+00 0.000000 0.000000e+00 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000e+00 0.000000
1.0 0.005142 0.010165 7.329284e-03 0.003846 1.616346e-03 0.007531 0.004451 0.013399 0.010005 0.005644 5.364228e-03 0.004686
2.0 0.047848 0.021472 9.391356e-03 0.008519 9.559839e-03 0.007702 0.003906 0.015483 0.013289 0.010247 4.932251e-03 0.002851
3.0 0.000399 0.001417 7.518097e-03 0.022323 3.168860e-02 0.000725 0.000003 0.000000 0.000086 0.000048 9.427925e-05 0.000038
4.0 0.000111 0.000121 8.071787e-04 0.003511 2.471323e-04 0.001164 0.004086 0.008253 0.005619 0.004474 9.256760e-04 0.002056
5.0 0.000038 0.000034 2.768550e-04 0.001126 3.547547e-04 0.000503 0.000714 0.002902 0.001704 0.000493 4.169282e-05 0.000027
6.0 0.000009 0.000000 5.775546e-07 0.000411 3.539126e-04 0.000742 0.005196 0.002755 0.000328 0.000063 6.417273e-08 0.000000
7.0 0.131240 0.050740 2.336556e-02 0.021442 5.823231e-02 0.116478 0.084967 0.199298 0.167210 0.131153 1.291310e-01 0.185322
8.0 0.022173 0.003343 2.504248e-03 0.006846 1.454145e-03 0.006521 0.026018 0.030221 0.009536 0.002109 4.103821e-04 0.003000
9.0 0.213033 0.082446 5.174180e-02 0.046706 1.590702e-02 0.077106 0.138105 0.213273 0.108346 0.082627 2.088284e-02 0.079759
10.0 0.001402 0.001310 5.057406e-04 0.000114 1.093030e-03 0.008488 0.004494 0.009044 0.007319 0.001840 5.139641e-04 0.000619
11.0 0.000000 0.000000 0.000000e+00 0.000000 1.656300e-07 0.000048 0.000596 0.000545 0.000006 0.000002 0.000000e+00 0.000000
12.0 0.014358 0.001890 2.213626e-03 0.003409 4.333056e-04 0.002435 0.003425 0.005738 0.004984 0.002687 8.249662e-04 0.000686
13.0 0.024282 0.001046 1.454654e-03 0.006853 6.898171e-03 0.006047 0.006822 0.019297 0.023798 0.013782 1.666349e-02 0.015513
14.0 0.001225 0.011850 1.625901e-02 0.011926 4.879781e-03 0.000457 0.000325 0.001730 0.000914 0.001412 4.983606e-04 0.000581
In [390]:
biomes_table['area'].size
Out[390]:
15
In [397]:
## test 2001 may bionum =  5 assert 3.547547e-04
bp = at_table_cp[at_table_cp.year == '2001'].groupby('biome_num').sum().iloc[5]['May']
area_5 = biomes_table['area'][5]
assert bp/area_5 == 3.547547e-04, print((bp/area_5 - 3.547547e-04 )*100/3.547547e-04)
7.73603425689e-06
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-397-801102fec9a9> in <module>()
      2 bp = at_table_cp[at_table_cp.year == '2001'].groupby('biome_num').sum().iloc[5]['May']
      3 area_5 = biomes_table['area'][5]
----> 4 assert bp/area_5 == 3.547547e-04, print((bp/area_5 - 3.547547e-04 )*100/3.547547e-04)

AssertionError: None
In [399]:
at_table_cp[at_table_cp.year == '2001'].groupby('biome_num').sum().div(biomes_table['area'], axis=0)[months].sum(axis=1)
Out[399]:
biome_num
0.0     0.000000
1.0     0.079177
2.0     0.155202
3.0     0.064339
4.0     0.031376
5.0     0.008214
6.0     0.009858
7.0     1.298579
8.0     0.114135
9.0     1.129932
10.0    0.036743
11.0    0.001197
12.0    0.043083
13.0    0.142456
14.0    0.052058
dtype: float64
In [400]:
biomes_inter = [at_table_cp[at_table_cp.year == yr].groupby('biome_num').sum().div(biomes_table['area'], axis=0)[months].sum(axis=1) for yr in years]
In [405]:
biomes_inter = DataFrame(biomes_inter).T
In [406]:
biomes_inter
Out[406]:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
biome_num
0.0 0.000000 2.243894e-07 4.737109e-07 1.495929e-07 1.994572e-07 7.479646e-07 1.495929e-07 1.246608e-07 0.000001 0.000000 1.246608e-07 3.241180e-07 2.493215e-08 0.000000 0.000000 4.986431e-08 0.000000
1.0 0.079177 1.123430e-01 1.450247e-01 1.579688e-01 1.607972e-01 1.258199e-01 1.786732e-01 1.142799e-01 0.134173 0.170478 1.075968e-01 1.281776e-01 1.091738e-01 0.117187 0.141210 1.258434e-01 0.112576
2.0 0.155202 1.757644e-01 2.077231e-01 2.702261e-01 2.120833e-01 1.832616e-01 2.536054e-01 1.910422e-01 0.178725 0.231761 1.937981e-01 2.127617e-01 1.619954e-01 0.152764 0.211524 1.804382e-01 0.196018
3.0 0.064339 7.794200e-02 1.282763e-01 5.042862e-02 1.642964e-01 9.353040e-02 8.062492e-02 1.127472e-01 0.100795 0.056061 2.416296e-01 1.253860e-01 1.042190e-01 0.048896 0.037499 8.945484e-02 0.128204
4.0 0.031376 4.223833e-02 4.111959e-02 3.776427e-02 4.224227e-02 5.747414e-02 4.156677e-02 6.615677e-02 0.057478 0.045769 4.349010e-02 4.599330e-02 3.134626e-02 0.048206 0.034964 2.562314e-02 0.032435
5.0 0.008214 3.635029e-02 3.547803e-02 7.607843e-03 1.101861e-02 1.674333e-02 2.534887e-02 3.821367e-02 0.013182 0.013034 2.268199e-02 3.611549e-02 2.412003e-02 0.021839 0.028419 1.494285e-02 0.037517
6.0 0.009858 2.369931e-02 3.649028e-02 1.416055e-02 1.425334e-02 1.522832e-02 9.486783e-03 1.903947e-02 0.011562 0.013420 1.863056e-02 2.851605e-02 2.284626e-02 0.027323 0.021218 1.596740e-02 0.015535
7.0 1.298579 1.250891e+00 1.344420e+00 1.406841e+00 1.420960e+00 1.276042e+00 1.406004e+00 1.280522e+00 1.181250 1.255011 1.306499e+00 1.316475e+00 1.140422e+00 1.142718 1.129316 1.170387e+00 1.115833
8.0 0.114135 1.451768e-01 1.100276e-01 9.041627e-02 1.093230e-01 1.148143e-01 9.472838e-02 1.320358e-01 0.063897 0.088387 6.727555e-02 7.292511e-02 2.787293e-02 0.095959 0.089387 5.639813e-02 0.097806
9.0 1.129932 1.806076e+00 1.144355e+00 1.419598e+00 1.416000e+00 1.284175e+00 1.416477e+00 1.405381e+00 1.518368 1.087008 1.338035e+00 1.330858e+00 1.153354e+00 1.131988 1.507309 1.247569e+00 1.129504
10.0 0.036743 4.601280e-02 5.374625e-02 3.358207e-02 4.297528e-02 3.940083e-02 3.731585e-02 3.717399e-02 0.032568 0.042290 3.961703e-02 3.391066e-02 3.200557e-02 0.032221 0.031252 2.282446e-02 0.030332
11.0 0.001197 1.884538e-03 6.590582e-03 6.994884e-03 2.212485e-03 7.931191e-04 1.518081e-03 1.131749e-03 0.001258 0.004726 7.354798e-04 1.137132e-03 9.068240e-04 0.000517 0.002330 3.165023e-03 0.001421
12.0 0.043083 5.512400e-02 6.041886e-02 5.492024e-02 5.283899e-02 3.976446e-02 5.048555e-02 3.205172e-02 0.051601 0.045217 3.046426e-02 4.617034e-02 2.986041e-02 0.043237 0.054750 4.268506e-02 0.076688
13.0 0.142456 1.820456e-01 3.635939e-02 7.813878e-02 5.020803e-02 9.958127e-02 7.904144e-02 5.513703e-02 0.032499 0.063060 1.955648e-01 1.439373e-01 3.833660e-02 0.060039 0.064319 2.779771e-02 0.114394
14.0 0.052058 9.113770e-02 1.477432e-01 1.426626e-01 1.243064e-01 1.608943e-01 1.158412e-01 9.289580e-02 0.135658 0.104843 1.157789e-01 1.012849e-01 1.136470e-01 0.138793 0.172287 1.221399e-01 0.088625

Mesma escala

In [414]:
fig, ax = plt.subplots(5,3, figsize =(18,12) , sharey=True)
labels = years[::2]
ax = ax.ravel()
for i in range(15):
        slope, intercept, r_value, p_value, std_err = stats.linregress(range(17), biomes_inter.iloc[i])
        ax[i].plot(years, intercept + slope*range(17), 'r', label=r"$R^2$: {:5.3f} ".format(r_value**2))
        ax[i].plot(years, biomes_inter.iloc[i], 'o', label='')
        ax[i].set_xticks(labels)
        ax[i].set_xticklabels(labels,fontsize=15)
        labels_y = ax[i].get_yticklabels()
        plt.setp(labels_y,fontsize=15)
        ax[i].set_title(biome_names_dict[i],fontsize=15)
        ax[i].legend(fontsize=15)         
fig.tight_layout()
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1316: UserWarning: findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

Sem escala comum

In [416]:
fig, ax = plt.subplots(5,3, figsize =(18,12) )
labels = years[::2]
ax = ax.ravel()
for i in range(15):
        #slope, intercept, r_value, p_value, std_err = stats.linregress(range(17), biomes_inter.iloc[i])
        #ax[i].plot(years, intercept + slope*range(17), 'r', label=r"$R^2$: {:5.3f} ".format(r_value**2))
        ax[i].plot(years, biomes_inter.iloc[i], label='')
        ax[i].set_xticks(labels)
        ax[i].set_xticklabels(labels,fontsize=15)
        labels_y = ax[i].get_yticklabels()
        plt.setp(labels_y,fontsize=15)
        ax[i].set_title(biome_names_dict[i],fontsize=15)
        ax[i].legend(fontsize=15)         
fig.tight_layout()
plt.show()
In [417]:
biomes_inter
Out[417]:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
biome_num
0.0 0.000000 2.243894e-07 4.737109e-07 1.495929e-07 1.994572e-07 7.479646e-07 1.495929e-07 1.246608e-07 0.000001 0.000000 1.246608e-07 3.241180e-07 2.493215e-08 0.000000 0.000000 4.986431e-08 0.000000
1.0 0.079177 1.123430e-01 1.450247e-01 1.579688e-01 1.607972e-01 1.258199e-01 1.786732e-01 1.142799e-01 0.134173 0.170478 1.075968e-01 1.281776e-01 1.091738e-01 0.117187 0.141210 1.258434e-01 0.112576
2.0 0.155202 1.757644e-01 2.077231e-01 2.702261e-01 2.120833e-01 1.832616e-01 2.536054e-01 1.910422e-01 0.178725 0.231761 1.937981e-01 2.127617e-01 1.619954e-01 0.152764 0.211524 1.804382e-01 0.196018
3.0 0.064339 7.794200e-02 1.282763e-01 5.042862e-02 1.642964e-01 9.353040e-02 8.062492e-02 1.127472e-01 0.100795 0.056061 2.416296e-01 1.253860e-01 1.042190e-01 0.048896 0.037499 8.945484e-02 0.128204
4.0 0.031376 4.223833e-02 4.111959e-02 3.776427e-02 4.224227e-02 5.747414e-02 4.156677e-02 6.615677e-02 0.057478 0.045769 4.349010e-02 4.599330e-02 3.134626e-02 0.048206 0.034964 2.562314e-02 0.032435
5.0 0.008214 3.635029e-02 3.547803e-02 7.607843e-03 1.101861e-02 1.674333e-02 2.534887e-02 3.821367e-02 0.013182 0.013034 2.268199e-02 3.611549e-02 2.412003e-02 0.021839 0.028419 1.494285e-02 0.037517
6.0 0.009858 2.369931e-02 3.649028e-02 1.416055e-02 1.425334e-02 1.522832e-02 9.486783e-03 1.903947e-02 0.011562 0.013420 1.863056e-02 2.851605e-02 2.284626e-02 0.027323 0.021218 1.596740e-02 0.015535
7.0 1.298579 1.250891e+00 1.344420e+00 1.406841e+00 1.420960e+00 1.276042e+00 1.406004e+00 1.280522e+00 1.181250 1.255011 1.306499e+00 1.316475e+00 1.140422e+00 1.142718 1.129316 1.170387e+00 1.115833
8.0 0.114135 1.451768e-01 1.100276e-01 9.041627e-02 1.093230e-01 1.148143e-01 9.472838e-02 1.320358e-01 0.063897 0.088387 6.727555e-02 7.292511e-02 2.787293e-02 0.095959 0.089387 5.639813e-02 0.097806
9.0 1.129932 1.806076e+00 1.144355e+00 1.419598e+00 1.416000e+00 1.284175e+00 1.416477e+00 1.405381e+00 1.518368 1.087008 1.338035e+00 1.330858e+00 1.153354e+00 1.131988 1.507309 1.247569e+00 1.129504
10.0 0.036743 4.601280e-02 5.374625e-02 3.358207e-02 4.297528e-02 3.940083e-02 3.731585e-02 3.717399e-02 0.032568 0.042290 3.961703e-02 3.391066e-02 3.200557e-02 0.032221 0.031252 2.282446e-02 0.030332
11.0 0.001197 1.884538e-03 6.590582e-03 6.994884e-03 2.212485e-03 7.931191e-04 1.518081e-03 1.131749e-03 0.001258 0.004726 7.354798e-04 1.137132e-03 9.068240e-04 0.000517 0.002330 3.165023e-03 0.001421
12.0 0.043083 5.512400e-02 6.041886e-02 5.492024e-02 5.283899e-02 3.976446e-02 5.048555e-02 3.205172e-02 0.051601 0.045217 3.046426e-02 4.617034e-02 2.986041e-02 0.043237 0.054750 4.268506e-02 0.076688
13.0 0.142456 1.820456e-01 3.635939e-02 7.813878e-02 5.020803e-02 9.958127e-02 7.904144e-02 5.513703e-02 0.032499 0.063060 1.955648e-01 1.439373e-01 3.833660e-02 0.060039 0.064319 2.779771e-02 0.114394
14.0 0.052058 9.113770e-02 1.477432e-01 1.426626e-01 1.243064e-01 1.608943e-01 1.158412e-01 9.289580e-02 0.135658 0.104843 1.157789e-01 1.012849e-01 1.136470e-01 0.138793 0.172287 1.221399e-01 0.088625
In [419]:
at_table_cp[at_table_cp.year == '2001'].groupby('biome_num').sum().div(biomes_table['area'], axis=0)[months].sum()
Out[419]:
Jan    0.461258
Feb    0.185835
Mar    0.123368
Apr    0.137031
May    0.132719
Jun    0.235945
Jul    0.283109
Aug    0.521938
Sep    0.353143
Oct    0.256580
Nov    0.180283
Dec    0.295140
dtype: float64

Variação intra-anual em cada clima

In [422]:
no_climas = len(set(climes));no_climas
Out[422]:
31
In [427]:
climes_table = at_table_cp.groupby('clime').agg(agg_dict)
In [428]:
climes_table[months].div(climes_table['area'], axis =0)
Out[428]:
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
clime
11 0.022156 0.043684 0.033929 0.021716 0.019614 0.015440 0.028431 0.087011 0.132103 0.101210 0.028395 0.019882
12 0.566471 0.565489 0.388668 0.234642 0.087165 0.054900 0.160505 0.258429 0.232427 0.178250 0.217658 0.337329
13 0.393273 0.752043 0.609540 0.499248 0.271224 0.064881 0.042956 0.041138 0.060788 0.070760 0.084253 0.149830
14 2.754740 1.213559 0.629694 0.426381 1.020535 1.797618 2.322354 2.651192 2.359992 1.267654 1.481602 3.484659
21 0.005224 0.007700 0.015477 0.014773 0.002746 0.007064 0.006297 0.008283 0.012441 0.014050 0.006161 0.003497
22 0.083584 0.038019 0.032321 0.035296 0.028603 0.020571 0.020044 0.068173 0.174859 0.303313 0.228358 0.098912
26 0.056209 0.031746 0.037197 0.054077 0.039769 0.237019 0.254850 0.245482 0.123015 0.058405 0.025493 0.031965
27 0.839854 0.532521 0.350290 0.341231 0.452640 0.407692 0.603197 1.222892 1.847486 2.304611 2.699321 1.413647
31 0.102782 0.091165 0.110131 0.097160 0.045985 0.085977 0.215810 0.247254 0.231665 0.143092 0.091856 0.066891
32 0.048389 0.039054 0.039349 0.013616 0.006835 0.028963 0.082440 0.108126 0.067426 0.043764 0.026700 0.031203
33 0.002235 0.005963 0.004579 0.000985 0.003367 0.000260 0.000147 0.000294 0.000344 0.000096 0.004466 0.004671
34 0.013683 0.011913 0.042048 0.093190 0.102254 0.143480 0.126217 0.158249 0.126633 0.091417 0.036726 0.012969
35 0.072037 0.044528 0.046096 0.050515 0.045718 0.040524 0.073129 0.190135 0.106520 0.063105 0.038914 0.040730
36 0.047557 0.022595 0.011333 0.000574 0.004232 0.001722 0.000000 0.000072 0.000143 0.001722 0.050785 0.017144
37 0.042334 0.127920 0.469416 0.292178 0.508782 1.173812 1.501279 2.836720 2.991417 1.146990 0.157923 0.047746
38 0.050469 0.092811 0.200494 0.109316 0.491931 0.995720 1.251859 1.341777 0.849657 0.389949 0.109940 0.036127
39 0.016992 0.029617 0.013317 0.027110 0.017208 0.003156 0.023824 0.056684 0.046826 0.016041 0.004194 0.004237
41 0.000284 0.002194 0.038349 0.054048 0.014904 0.268560 0.532716 0.756104 0.451491 0.218448 0.005011 0.000495
42 0.000129 0.005105 0.057479 0.216428 0.082961 0.033787 0.104930 0.193069 0.153622 0.094761 0.005480 0.000481
43 0.000032 0.000082 0.000874 0.014100 0.012926 0.040012 0.087495 0.048193 0.011745 0.001334 0.000269 0.000068
44 0.000000 0.000000 0.000000 0.006950 0.002446 0.017931 0.109064 0.070905 0.010106 0.000029 0.000000 0.000000
45 0.000818 0.001608 0.017776 0.031203 0.028111 0.145014 0.264811 0.342210 0.289369 0.086841 0.016512 0.002199
46 0.000009 0.000241 0.004105 0.005279 0.001751 0.007064 0.072181 0.117757 0.080626 0.029224 0.010382 0.000828
47 0.000031 0.000003 0.000095 0.000403 0.002762 0.043945 0.093496 0.087241 0.017431 0.000259 0.000056 0.000026
48 0.000000 0.000000 0.000000 0.000000 0.000375 0.002458 0.013295 0.014951 0.019367 0.000007 0.000000 0.000000
49 0.012171 0.037295 0.196675 0.315510 0.017990 0.018125 0.004437 0.004188 0.052189 0.149456 0.184012 0.005130
50 0.001265 0.023733 0.371959 0.791050 0.285908 0.039400 0.019636 0.024535 0.101703 0.331284 0.089059 0.003676
51 0.000329 0.001531 0.246757 0.182467 0.263784 0.102071 0.101247 0.051560 0.069110 0.036044 0.002635 0.000090
52 0.000000 0.000000 0.000000 0.032043 0.021378 0.025058 0.187763 0.081753 0.036298 0.000042 0.000000 0.000000
61 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
62 0.000127 0.000069 0.000089 0.000124 0.000399 0.001442 0.005748 0.006609 0.001325 0.000454 0.000147 0.000128
In [430]:
climes_intra = climes_table[months].div(climes_table['area'], axis =0)

Mesma escala

In [431]:
climanames  = [e['Clima_Name'] for e in ecos_info]
In [434]:
climes_intra.index[0]
Out[434]:
11
In [432]:
clima_names_dict = dict( (num, name) for num, name in zip(climes, climanames))
In [466]:
# 11 x 3, 31 climas
fig, ax = plt.subplots(nrows=11,ncols=3, figsize =(18,40) , sharey=True)
labels = months
ax = ax.ravel()
for i in range(31):
        #slope, intercept, r_value, p_value, std_err = stats.linregress(np.arange(12), monbio[i*3 + j])
        #ax[i][j].plot(months, intercept + slope*years_float, 'r', label=r"$R^2$: {:5.3f} ".format(r_value**2))
        ax[i].plot(months, climes_intra.iloc[i], 'o')
        ax[i].set_xticks(np.arange(12)) 
        ax[i].set_xticklabels(labels,fontsize=15)
        labels_y = ax[i].get_yticklabels()
        plt.setp(labels_y,fontsize=15)
        ax[i].set_title(clima_names_dict[climes_intra.index[i]],fontsize=15)
        #ax[i].legend(fontsize=15)
for i in range(31,33):
    ax[i].set_visible(False)
fig.tight_layout()
plt.show()

Sem escala comum

In [467]:
fig, ax = plt.subplots(nrows=11,ncols=3, figsize =(18,40) )
labels = months
ax = ax.ravel()
for i in range(31):
        #slope, intercept, r_value, p_value, std_err = stats.linregress(np.arange(12), monbio[i*3 + j])
        #ax[i][j].plot(months, intercept + slope*years_float, 'r', label=r"$R^2$: {:5.3f} ".format(r_value**2))
        ax[i].plot(months, climes_intra.iloc[i], 'o')
        ax[i].set_xticks(np.arange(12)) 
        ax[i].set_xticklabels(labels,fontsize=15)
        labels_y = ax[i].get_yticklabels()
        plt.setp(labels_y,fontsize=15)
        ax[i].set_title(clima_names_dict[climes_intra.index[i]],fontsize=15)
        #ax[i].legend(fontsize=15)
for i in range(31,33):
    ax[i].set_visible(False)
fig.tight_layout()
plt.show()
Köppen climate classification scheme symbols description table
1st 2nd 3rd
A (Tropical) f (Rainforest)
m (Monsoon)
w (Savanna, Wet)
s (Savanna, Dry)
B (Arid) W (Desert)
S (Steppe)
h (Hot)
k (Cold)
n (With frequent fog)
C (Temperate) s (Dry summer)
w (Dry winter)
f (Without dry season)
a (Hot summer)
b (Warm summer)
c (Cold summer)
D (Cold (continental)) s (Dry summer)
w (Dry winter)
f (Without dry season)
a (Hot summer)
b (Warm summer)
c (Cold summer)
d (Very cold winter)
E (Polar) T (Tundra)
F (Eternal winter (ice cap))
In [471]:
clima_names_dict.values()
Out[471]:
dict_values(['EF', 'Af', 'Cfa', 'Csb', 'Cfb', 'Csa', 'Dsa', 'Dsb', 'Dsc', 'ET', 'BSk', 'Dfc', 'BWh', 'BWk', 'Dwb', 'Dwc', 'Cfc', 'BSh', 'Dfb', 'As', 'Am', 'Aw', 'Cwb', 'Dfa', 'Cwa', 'Dwa', 'Cwc', 'Dwd', 'Dfd', 'Dsd', 'Csc'])

Variação inter-anual em cada clima

In [488]:
at_table_cp[at_table_cp['year']=='2001'].groupby('clime').sum().div(climes_table['area'], axis=0)[months].sum(axis=1)
Out[488]:
clime
11    0.011575
12    0.124069
13    0.170072
14    1.208360
21    0.007533
22    0.132140
26    0.074745
27    0.947267
31    0.107219
32    0.034865
33    0.000704
34    0.045285
35    0.024937
36    0.003156
37    0.499174
38    0.368163
39    0.008561
41    0.187127
42    0.044468
43    0.004183
44    0.034845
45    0.057823
46    0.015747
47    0.011706
48    0.006697
49    0.023925
50    0.098338
51    0.009207
52    0.039561
61    0.000000
62    0.000873
dtype: float64
In [493]:
climas_inter = [at_table_cp[at_table_cp['year']==yr].groupby('clime').sum().div(climes_table['area'], axis=0)[months].sum(axis=1) for yr in years]
In [495]:
climas_inter = DataFrame(climas_inter).T
In [496]:
climas_inter
Out[496]:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
clime
11 0.011575 0.047901 0.033304 0.053045 0.032870 0.054398 0.025429 0.020517 0.037834 0.031721 0.027098 0.025767 0.019888 0.040293 0.052672 0.025181 0.014078
12 0.124069 0.174274 0.228291 0.249845 0.248968 0.186131 0.247729 0.177872 0.188147 0.198409 0.164174 0.172941 0.163561 0.183577 0.205511 0.201126 0.167306
13 0.170072 0.192537 0.169943 0.195952 0.205052 0.162623 0.215448 0.200349 0.193689 0.171166 0.183714 0.217495 0.146074 0.131532 0.139276 0.151597 0.193416
14 1.208360 1.277196 1.380311 1.358817 1.493153 1.246251 1.439250 1.271806 1.180962 1.322620 1.216608 1.252754 1.127569 1.133039 1.163675 1.224822 1.112786
21 0.007533 0.003499 0.007499 0.006002 0.007585 0.011359 0.008500 0.003863 0.005922 0.002717 0.004900 0.006952 0.006113 0.005589 0.005647 0.003123 0.006910
22 0.132140 0.146483 0.025411 0.040089 0.033463 0.071090 0.058288 0.037381 0.027806 0.039777 0.172012 0.150265 0.034745 0.044348 0.036525 0.020819 0.061412
26 0.074745 0.134271 0.063635 0.098124 0.095871 0.104214 0.059620 0.044483 0.035727 0.070355 0.060542 0.049909 0.022038 0.055165 0.071140 0.035956 0.119435
27 0.947267 0.850821 0.636033 0.950223 0.671710 0.808511 0.837436 0.739867 0.694139 0.661390 1.020937 0.913395 0.629577 0.656470 0.693183 0.574394 0.730030
31 0.107219 0.077776 0.099826 0.097809 0.100353 0.106633 0.098591 0.117790 0.088571 0.071388 0.109064 0.081497 0.070140 0.069399 0.067864 0.074443 0.091405
32 0.034865 0.035888 0.058827 0.021612 0.032621 0.036378 0.040168 0.027818 0.031121 0.025335 0.025164 0.029952 0.026529 0.029278 0.026225 0.027603 0.026481
33 0.000704 0.000340 0.001895 0.000407 0.003057 0.000751 0.001736 0.005153 0.000658 0.000122 0.002721 0.000616 0.001161 0.002629 0.001417 0.003577 0.000461
34 0.045285 0.062381 0.072631 0.060570 0.046005 0.040608 0.067912 0.035967 0.060740 0.064620 0.059989 0.057593 0.043080 0.044908 0.061911 0.059144 0.075435
35 0.024937 0.043524 0.038443 0.034122 0.050085 0.060860 0.039218 0.038358 0.065236 0.035452 0.071677 0.050511 0.041396 0.027509 0.057230 0.040113 0.093281
36 0.003156 0.024891 0.025823 0.005236 0.000574 0.001793 0.007747 0.008034 0.034144 0.000000 0.008321 0.007245 0.002941 0.010616 0.000861 0.014561 0.001937
37 0.499174 0.557876 0.703615 0.713663 0.746670 0.642590 0.760498 0.655174 0.625755 0.756728 0.682854 0.741012 0.681215 0.629012 0.663761 0.635290 0.601629
38 0.368163 0.327497 0.372279 0.353971 0.405368 0.364862 0.388283 0.354729 0.383436 0.406427 0.346056 0.319744 0.329812 0.325080 0.294490 0.285506 0.294348
39 0.008561 0.005405 0.020538 0.002335 0.037789 0.012236 0.010377 0.016517 0.025207 0.031174 0.001211 0.022397 0.019284 0.018289 0.009858 0.012323 0.005707
41 0.187127 0.267371 0.148198 0.154484 0.207875 0.224452 0.124151 0.183326 0.112250 0.181760 0.024149 0.089188 0.011634 0.126672 0.080602 0.037658 0.181708
42 0.044468 0.097416 0.053465 0.067427 0.062530 0.066873 0.056356 0.115727 0.065106 0.068515 0.032706 0.048227 0.013941 0.055796 0.036797 0.022389 0.040493
43 0.004183 0.017435 0.015497 0.012541 0.010077 0.012192 0.007201 0.009456 0.005098 0.013512 0.011476 0.018179 0.019466 0.016136 0.013541 0.015830 0.015306
44 0.034845 0.039724 0.008099 0.000210 0.012040 0.001226 0.000980 0.005495 0.009747 0.003081 0.013784 0.039075 0.016899 0.021847 0.001168 0.000629 0.008581
45 0.057823 0.147516 0.150498 0.149955 0.091836 0.090387 0.130907 0.045743 0.064076 0.060091 0.055549 0.024277 0.026421 0.046128 0.028578 0.011606 0.045083
46 0.015747 0.028035 0.012606 0.014332 0.018922 0.043853 0.043519 0.016810 0.005739 0.011895 0.019049 0.018604 0.016782 0.021072 0.017529 0.012720 0.012232
47 0.011706 0.007101 0.026391 0.057113 0.024488 0.003404 0.002951 0.006657 0.017994 0.014878 0.000979 0.002820 0.010975 0.026236 0.016014 0.007382 0.008660
48 0.006697 0.002274 0.032642 0.000210 0.001801 0.000026 0.002425 0.000000 0.000013 0.002852 0.000112 0.000000 0.000092 0.000723 0.000230 0.000296 0.000059
49 0.023925 0.019959 0.040544 0.019433 0.027211 0.014342 0.032726 0.034934 0.041020 0.014110 0.061834 0.025465 0.039405 0.182138 0.145673 0.040834 0.233624
50 0.098338 0.093293 0.234577 0.068153 0.118770 0.105394 0.100296 0.274307 0.106550 0.037949 0.117511 0.095389 0.077843 0.182681 0.138756 0.115734 0.117666
51 0.009207 0.064412 0.234622 0.013049 0.038373 0.046451 0.062168 0.117971 0.030887 0.014465 0.073008 0.060466 0.024447 0.096608 0.109116 0.032451 0.029923
52 0.039561 0.032434 0.033560 0.000119 0.013744 0.002682 0.001969 0.017650 0.034529 0.016795 0.022169 0.115632 0.021992 0.009522 0.003050 0.000520 0.018405
61 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
62 0.000873 0.000832 0.002046 0.000626 0.000836 0.000564 0.000559 0.001169 0.001914 0.002270 0.000450 0.001267 0.000668 0.000392 0.000680 0.000874 0.000645

Mesma escala

In [500]:
fig, ax = plt.subplots(nrows=11,ncols=3, figsize =(18,40) , sharey=True)
labels = years[::2]
ax = ax.ravel()
for i in range(31):
        slope, intercept, r_value, p_value, std_err = stats.linregress(range(17), climas_inter.iloc[i])
        ax[i].plot(years, intercept + slope*range(17), 'r', label=r"$R^2$: {:5.3f} ".format(r_value**2))
        ax[i].plot(years, climas_inter.iloc[i], 'o', label='')
        ax[i].set_xticks(labels)
        ax[i].set_xticklabels(labels,fontsize=15)
        labels_y = ax[i].get_yticklabels()
        plt.setp(labels_y,fontsize=15)
        ax[i].set_title(clima_names_dict[climas_inter.index[i]],fontsize=15)
        ax[i].legend(fontsize=15)
for i in range(31,33):
    ax[i].set_visible(False)
fig.tight_layout()
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1316: UserWarning: findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

Escala comum

In [501]:
fig, ax = plt.subplots(nrows=11,ncols=3, figsize =(18,40) )
labels = years[::2]
ax = ax.ravel()
for i in range(31):
        slope, intercept, r_value, p_value, std_err = stats.linregress(range(17), climas_inter.iloc[i])
        ax[i].plot(years, intercept + slope*range(17), 'r', label=r"$R^2$: {:5.3f} ".format(r_value**2))
        ax[i].plot(years, climas_inter.iloc[i], 'o', label='')
        ax[i].set_xticks(labels)
        ax[i].set_xticklabels(labels,fontsize=15)
        labels_y = ax[i].get_yticklabels()
        plt.setp(labels_y,fontsize=15)
        ax[i].set_title(clima_names_dict[climas_inter.index[i]],fontsize=15)
        ax[i].legend(fontsize=15)
for i in range(31,33):
    ax[i].set_visible(False)
fig.tight_layout()
plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1316: UserWarning: findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

Variação inter-anual por mês em cada bioma

In [530]:
groupedby_year_clima = at_table_cp.groupby(['clime','year']).sum()
In [531]:
groupedby_year_clima = groupedby_year_clima[months].div(groupedby_year_clima.area, axis =0)
In [537]:
groupedby_year_clima =groupedby_year_clima.reset_index()
In [544]:
groupedby_year_clima[groupedby_year_clima['clime'] == 11][months].T.iloc[0]
Out[544]:
0     0.000524
1     0.000833
2     0.001988
3     0.001957
4     0.001493
5     0.000529
6     0.000994
7     0.001154
8     0.000774
9     0.001585
10    0.001423
11    0.001180
12    0.000899
13    0.001217
14    0.000736
15    0.003823
16    0.001047
Name: Jan, dtype: float64
In [567]:
labels = years[::2]
for climcode in clima_names_dict.keys():
    df = groupedby_year_clima[groupedby_year_clima['clime'] == climcode][months].T
    fig, ax = plt.subplots(4,3, figsize =(20,12) , sharey= True)
    ax = ax.ravel()
    fig.suptitle(clima_names_dict[climcode],fontsize=15)
    for i in range(12):
        data = df.iloc[i]
        slope, intercept, r_value, p_value, std_err = stats.linregress(range(17), data)
        ax[i].plot(years, intercept + slope*range(17), 'r', label=r"$R^2$: {:5.3f} ".format(r_value**2))
        ax[i].plot(years, data, 'o', label='_nolegend_')
        ax[i].set_xticks(labels) 
        ax[i].set_xticklabels(labels,fontsize=15)
        labels_y = ax[i].get_yticklabels()
        plt.setp(labels_y,fontsize=15)
        ax[i].set_title(calendar.month_name[i +1],fontsize=15)
        ax[i].legend(fontsize=15)
    fig.tight_layout(rect=[0, 0.03, 1, 0.95])
    plt.show()
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1316: UserWarning: findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
In [569]:
labels = years[::2]
for climcode in clima_names_dict.keys():
    df = groupedby_year_clima[groupedby_year_clima['clime'] == climcode][months].T
    fig, ax = plt.subplots(4,3, figsize =(20,12) )
    ax = ax.ravel()
    fig.suptitle(clima_names_dict[climcode],fontsize=15)
    for i in range(12):
        data = df.iloc[i]
        #slope, intercept, r_value, p_value, std_err = stats.linregress(range(17), data)
        #ax[i].plot(years, intercept + slope*range(17), 'r', label=r"$R^2$: {:5.3f} ".format(r_value**2))
        ax[i].plot(years, data, 'o', label='_nolegend_')
        ax[i].set_xticks(labels) 
        ax[i].set_xticklabels(labels,fontsize=15)
        labels_y = ax[i].get_yticklabels()
        plt.setp(labels_y,fontsize=15)
        ax[i].set_title(calendar.month_name[i +1],fontsize=15)
        ax[i].legend(fontsize=15)
    fig.tight_layout(rect=[0, 0.03, 1, 0.95])
    plt.show()
In [592]:
# as linhas seguintes dão o mesmo resultado
at_table_cp.groupby(['year','clime']).sum()[months];

pd.pivot_table(at_table_cp, values=months, index=['year', 'clime'],aggfunc=np.sum)[months];
In [593]:
notincluded13 = pickle.loads(open('notincluded2013','rb').read())

df_notinc13 = DataFrame(notincluded13)

df_notinc13.to_csv('not_included13.csv', header=False)
In [610]:
notincluded17 = pickle.loads(open('notincluded2017','rb').read())

df_notinc17 = DataFrame(notincluded17)

df_notinc17.to_csv('not_included17.csv', header=False)